def solve(gas, cost):
    n = len(gas)

    for i in range(n):
        gasSum = 0
        costSum = 0
        steps = 0
        for j in range(i, n + i):
            gasSum += gas[j % n]
            costSum += cost[j % n]
            if gasSum < costSum:
                i = j
                break
            steps += 1
        if steps == n:
            return i

    return -1


if __name__ == "__main__":
    # gas = [1, 2, 3, 4, 5]
    # cost = [3, 4, 5, 1, 2]
    gas = [2, 3, 4]
    cost = [3, 4, 3]
    print(solve(gas, cost))
